package com.examine.serviceImpl;

import com.examine.bean.User;
import com.examine.bean.UserReplenish;
import com.examine.dao.UserMapper;
import com.examine.dao.UserReplenishMapper;
import com.examine.service.UserReplenishService;
import com.examine.utils.DataConfig;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class UserReplenishServiceImpl implements UserReplenishService {
    private static SqlSession session = null;
    private static UserReplenishMapper userReplenishMapper = null;
    private UserReplenish userReplenish = null;
    private int count = 0;

    public static void dataConfig(){
        try{
            session = DataConfig.getSession();
            userReplenishMapper = session.getMapper(UserReplenishMapper.class);
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    @Override
    public int deleteByPrimaryKey(String id) {
        dataConfig();

        try{
            count = userReplenishMapper.deleteByPrimaryKey(id);
            if (count > 0){
                session.commit();
            }

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }
        return count;
    }

    @Override
    public int insertSelective(UserReplenish record) {
        dataConfig();

        try{
            count = userReplenishMapper.insertSelective(record);
            if (count > 0){
                session.commit();
            }

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }
        return count;
    }

    @Override
    public UserReplenish selectByPrimaryKey(String id) {
        dataConfig();

        try{
            userReplenish = userReplenishMapper.selectByPrimaryKey(id);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }
        return userReplenish;
    }

    @Override
    public int updateByPrimaryKeySelective(UserReplenish record) {
        dataConfig();

        try{
            count = userReplenishMapper.updateByPrimaryKeySelective(record);
            if (count > 0){
                session.commit();
            }

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }
        return count;
    }

    @Override
    public UserReplenish userClassGradeInfo(UserReplenish record) {
        dataConfig();

        try{
            userReplenish = userReplenishMapper.userClassGradeInfo(record);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }
        return userReplenish;
    }
}
